package tt.dz.appaction;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import tt.dz.appaction.base.BaseController;
import tt.dz.common.Constants;
import tt.dz.common.PublicFunc;
import tt.dz.service.UserWalletService;


/**
 * 用户账户控制
 * @author xielf
 *
 */
@Controller
@RequestMapping("/userWallet")
public class UserWalletController extends BaseController{

	
	/**用户账户业务接口*/
	@Resource
	UserWalletService userWalletService;
	
	/**
	 * 得到用户余额
	 * @param request
	 * @param response
	 */
	@RequestMapping("getUserBalance.do")
	public void getUserBalance(String cardNum,HttpServletRequest request,HttpServletResponse response){
		
		/**获取用户余额信息*/
		Double balance = userWalletService.getUserWalletBalanceByCardNum(cardNum);

		/**获取用户冻结金额*/
		Double freezeSum = userWalletService.getUserWalletFreezeSum(cardNum);
		
		//JSON节点MAP
		Map<String,Double> resultMap = new HashMap<String,Double>();
		resultMap.put("balance", balance);
		resultMap.put("freezeSum",freezeSum);
		String resultStr = "";
		//失败就返回-99（service实现类自定义）
		if(balance.doubleValue()==-99.0 || freezeSum.doubleValue()==-99.0){
			resultStr = PublicFunc.getOutStr(Constants.JsonResponseCode.FAIL, "err", null);
		}
		else{
			resultStr = PublicFunc.getOutStr(Constants.JsonResponseCode.SUCCESS, "ok", resultMap);
		}
		this.outText(resultStr, response);//返回至客户端
	}
	
}
